﻿myApp.controller('EventDetailController', function ($scope, $http, $routeParams, $filter, NgMap, $location,$rootScope) {

    //$scope.share = {};
    $scope.isAndroid = $rootScope.isAndroid;
    $scope.isSearch = true;

    var BASE_URL;
    if ($location.host() == "localhost") {
        BASE_URL = $location.protocol() + "://" + "localhost:" + $location.port();
    } else {
        BASE_URL = $location.protocol() + "://" + $location.host();
    }

    $scope.current_path_url = $location.absUrl();




    pageInit();
    function pageInit() {
        var url = 'api/Events/GetEvent/' + $routeParams.id;
        $http.get(url).success(function (data) {
            $scope.EventPhoto = data.pictureList[0].PropertyURL;
            $scope.Event = data.Events;
            $scope.Event.StartDateTime = new Date($scope.Event.StartDateTime);
            $scope.Event.EndDateTime = new Date($scope.Event.EndDateTime);
            $scope.slides = data.pictureList;


            $scope.EventDetails = data.Events.Details.replace(new RegExp('\r?\n', 'g'), '<br />');


            $scope.shareTitle = data.Events.Name;
            $scope.shareDescription = data.Events.Venue;
            $scope.shareURL = BASE_URL + "/info/events/details/" + $routeParams.id;
            $scope.shareImageURL = data.pictureList[0].pictureURL || "http://www.penangrealty.my/images/penang realty,Apartment,house,condominium,terrace house,semi d,detached,bungalow,high end luxury properties,landed properties,gated guarded house.png";

            $scope.googleShareURL = encodeURI(encodeURI($scope.shareURL));

            $scope.isSearch = false;

            //            $scope.share.url = 'http://www.penangrealty.my/EventDetail/' + $routeParams.id.toString();
            //            $scope.share.pictureUrl = $scope.slides ? $scope.slides[0].pictureURL : 'http://www.penangrealty.my/images/penang realty,Apartment,house,condominium,terrace house,semi d,detached,bungalow,high end luxury properties,landed properties,gated guarded house.png';
            //            $scope.share.description = "[" + $scope.Event.Name + '] ' + $scope.Event.Venue + "\n" + $scope.Event.StartDateTime + " - " + $scope.Event.EndDateTime
            //+ '\n' + $scope.Event.Details + '\n' + window.location.href + '\n';

            //            document.title = "Penang Realty 世界地產 " + $scope.Event.Name;
            //            $scope.$emit('newPageLoaded', { 'title': $scope.Event.Name, 'description': $scope.share.description });
        }).error(function (err) {
            $scope.isSearch = false;

            alert("There is problem loading...");

        });

    }

    $scope.submitForm = function (obj) {
        var url = 'https://script.google.com/macros/s/AKfycbwcomu5o2CIbkO1lCjyZhDrF_dejSPWi0VAj9knYKYRr3jHDUY/exec';
        $http({
            method: 'POST',
            url: url,
            data: $(obj.target).serialize(),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (data) {
            alert("Thanks for Subscribing to our Newsletter!");
            $scope.subscription_email = "";
        });
    }



});